package com.net.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;

import android.os.Environment;

public class NetInfo {
	private File isExitFile() {
		File file = new File("/proc/self/net/dev");
		if (!file.exists()) {
			file = new File("/proc/net/dev");
			if (file.exists()) {
				return file;
			}
		} else {
			return file;
		}
		return null;
	}

	private static HashMap<String, Long> transmit = new HashMap<String, Long>();
	private static HashMap<String, Long> receive = new HashMap<String, Long>();

	public void readFile(File file) {
		if (file == null) {
			System.out.println("文件不存在");
			return;
		}
		try {
			ArrayList<String> list = new ArrayList<String>();
			BufferedReader br = new BufferedReader(new FileReader(file));
			String temp = null;
			while ((temp = br.readLine()) != null) {
				list.add(temp);
			}
			br.close();
			int len = list.size();
			for (int i = 2; i < len; i++) {
				String[] key_value = list.get(i).split(":");
				String[] nums=cutSpace(key_value[1]);
				
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String[] cutSpace(String str) {
		int len = str.length();
		int begin = -1;
		int end = 0;
		ArrayList<String> list = new ArrayList<String>(20);
		for (int i = 0; i < len; i++) {
			if (str.charAt(i) == ' ') {
				end = i;
				if (end - begin < 2) {
					begin = end;
					continue;
				}
				list.add(str.substring(begin + 1, end));
				begin = end;
			}
		}
		if (end != len - 1) {
			list.add(str.substring(begin + 1, len));
		}
		return list.toArray(new String[list.size()]);
	}
}
